﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<BlogRecentPostsSettingsViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <%= Html.GetCssFile(Url.GetModuleCssPath("MvcEngine.Blog.BackOffice.css")) %>
    <title>
        <%= this.Model.Localize("RecentPostsPageTitle")%>
    </title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.SuccessNotification("successNotification", Model.Localize("RecentPostsSuccessNotification"))%>
    <%= Html.ErrorNotification("errorNotification", Model.Localize("RecentPostsErrorNotification"))%>
    <div class="page-title" id="pages-header">
        <h1>
            <%= Model.Localize("RecentPostsSettingsPageHeader")%></h1>
    </div>
    <div class="page-menu">
        <%= Html.UrlActionLink(Model.Localize("SaveLink"), "javascript:void(0);", "Save();return false;")%>
    </div>
    <div id="blog-overview-settings">
        <% using (Html.BeginForm(Url.RecentPosts(), new { id = "settingsForm" }))
           {%>
        <div id="accordion" class="accordion">
            <h3>
                <a href="#">
                    <%= Model.Localize("BlogRecentPostsGeneralTabTitle")%></a></h3>
            <div>
                <div class="blog-overview-settings-form">
                    <%= Html.EditorFor(m => m.PostCount)%>
                </div>
            </div>
        </div>
        <%= Html.MvcEngineAntiForgeryToken(m => m.AntiForgeryToken)%>
        <%} %>
    </div>

    <script type="text/javascript">

        $(function() {
            $("#accordion").accordion({
                autoHeight: false
            });
        });

        function Save() {
            var options = {
                success: function(data) {
                    var json = JSON.parse(data);
                    $('.notification').hide('fast');
                    if (json.model != "valid") {
                        $('#errorNotification').show('fast');
                        var result = "<ul>";
                        for (var i in json.errors) {
                            result += "<li>" + json.errors[i] + "</li>";
                        }
                        result += "</ul>";
                        $('#errorNotification .notification-msg-content').html(result);
                    }
                    else {
                        $('#successNotification').show('fast');
                    }
                },
                error: function(request, textStatus, errorThrown) {
                    $('.notification').hide('fast');
                    $('#errorNotification').show('fast');
                }
            };
            $('#settingsForm').ajaxSubmit(options);
        }
        
    </script>

</asp:Content>
